package com.authority.framework.web.service.impl;

import com.authority.framework.base.service.impl.BaseServiceImpl;
import com.authority.framework.web.domain.SysRoleEntity;
import com.authority.framework.web.service.SysRoleService;
import org.beetl.sql.core.SQLManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: authority
 * @description: 角色 impl层
 * @author: Mr.Yan
 * @create: 2018-11-15 13:47
 **/
@Service
@Transactional
public class SysRoleServiceImpl extends BaseServiceImpl<SysRoleEntity> implements SysRoleService {

	@Autowired
	private SQLManager sqlManager;

	private Map<String, String> paramMap = null;

	/**
	 * 查询用户的角色
	 *
	 * @param userId
	 * @return
	 */
	@Override
	public List<SysRoleEntity> findListByUserId(Integer userId) {
		paramMap = new HashMap<>();
		paramMap.put("userId", userId.toString());
		return sqlManager.select("system/SysRoleSql.findListByUserId", SysRoleEntity.class, paramMap);
	}


	/**
	 * 删除角色以前的菜单
	 * @param roleId
	 * @return
	 */
	@Override
	public Integer deleteRoleMenu(String roleId) {
		paramMap = new HashMap<>();
		paramMap.put("roleId",roleId.toString());
		return  sqlManager.update("system/SysRoleMenu.deleteRoleMenu",paramMap);
	}

	@Override
	public Integer deleteRoleDept(String roleId) {
		paramMap = new HashMap<>();
		paramMap.put("roleId",roleId.toString());
		return  sqlManager.update("system/SysRoleDept.deleteRoleDept",paramMap);
	}
}


